package dome1;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: DickYang
 * Date: 2023-06-28
 * Time: 11:52
 *
 * 杨辉三角
 */
public class Test {
    public List<List<Integer>> generate(int numRows) {
        List<List<Integer>> ret = new ArrayList<>();
        List<Integer> row = new ArrayList<>();
        row.add(1);
        ret.add(row);
        for (int i = 1; i < numRows; i++) {
            List<Integer> curRow = new ArrayList<>();
            //第一个1
            curRow.add(1);
            //中间的赋值
            for (int j = 1; j < i; j++) {
                List<Integer> pervRow = ret.get(i-1);
                int x = pervRow.get(j-1) + pervRow.get(j);
                curRow.add(x);
            }
            //最后一个1
            curRow.add(1);

            ret.add(curRow);
        }
        return ret;
    }
    public static void main(String[] args) {
        Test test = new Test();
        List<List<Integer>> ret = test.generate(3);
        System.out.println(ret);
    }
}
